<template>
    <div>
        <el-row class="layout-page-heading">
            <el-col :span="16">
                <h3>财务管理</h3>
                <el-breadcrumb separator="/">
                    <el-breadcrumb-item>财务管理</el-breadcrumb-item>
                    <el-breadcrumb-item>充值记录</el-breadcrumb-item>
                    <el-breadcrumb-item>充值</el-breadcrumb-item>
                </el-breadcrumb>
            </el-col>
            <el-col :span="8">
                <div class="layout-page-heading-action">
                    <el-button onclick="router.go(-1)"><i class="fa fa-chevron-left"></i>返回</el-button>
                    <el-button type="primary" @click="save"><i class="fa fa-save"></i>保存</el-button>
                </div>
            </el-col>
        </el-row>
        <div class="layout-page-box">
            <!--<el-form :model="user" :rules="rules" ref="user" class="search-form">-->
            <el-form label-width="110px" label-position="right" :model="order" :rules="rules" ref="order"
                     class="edit-form">
                <el-form-item label="商户">
                    <el-select clearable v-model="order.agent_id">
                        <el-option :value="item.id" :label="item.name" v-for="item in agentList" :key="item.id">
                            {{item.name}}
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="充值金额(元)">
                    <el-input v-model="order.amount" placeholder="充值金额"></el-input>
                </el-form-item>
                <el-form-item label="备注">
                    <el-input type="textarea" rows="5" v-model="order.remark" placeholder="备注"></el-input>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
    export default {
        data(){
            return {
                order: {
                    agent_id: '',
                    amount: 0,
                    remark: ''
                },
                rules: {

                },
                agentList: []
            }
        },
        methods: {
            save(){
                var data = {
                    agent_id: this.order.agent_id,
                    amount: this.order.amount,
                    remark: this.order.remark
                };

                this.$refs.order.validate((valid) => {
                    if (valid) {
                        api.request('finance/recharge/add', data, 'POST').then((res) => {
                            _g.toast('success', '保存成功');
                            router.go(-1);
                        })
                    }
                })
            },
            getList(){
                api.request('info/agent/all', {}, 'POST').then((res) => {
                    this.agentList = res.data
                })
            }
        },
        mounted(){
            this.getList()
        },
        created() {

        }
    }
</script>

<style scoped>


</style>